
module Absyn

type typ =
  | TypeInt   
  | TypeShort 
  | TypeLong                          
  | TypeChar 
  | TypeFloat 
  | TypeDouble
  | TypeString
  | TypeBoolean                          
  | TypeArray of typ * int option         (* Array type                  *)
  | TypePoint of typ                      (* Pointer type                *)
                                                                   
and expr =                                                         
  | Access of access                 (* x    or  *p    or  a[e]     *)
  | Assign of access * expr          (* x=e  or  *p=e  or  a[e]=e   *)
  | Addr of access                   (* &x   or  &*p   or  &a[e]    *)
  | ConstInt of int                      (* Constant                    *)
  | ConstString of string (*constant string*)
  | ConstFloat of float32 (*constant float*)
  | ConstDouble of double  (*constant float*)
  | ConstChar of char (*constant char*) 
  | ConstLong of int64  (*constant long*)
  | Prim1 of string * expr           (* Unary primitive operator    *)
  | Prim2 of string * expr * expr    (* Binary primitive operator   *)
  | Prim3 of expr * expr * expr       (* triary primitive operator   *)
  | Andalso of expr * expr           (* Sequential and              *)
  | Orelse of expr * expr            (* Sequential or               *)
  | Call of string * expr list       (* Function call f(...)        *)
  | Max of expr * expr               (* Max function                *)
  | Min of expr * expr               (* Min function                *)
  | Abs of expr                      (* Abs function                *)

                                         
and access =                                                       
  | AccVar of string                 (* Variable access        x    *) 
  | AccDeref of expr                 (* Pointer dereferencing  *p   *)
  | AccIndex of access * expr        (* Array indexing         a[e] *)
                                                                   
and stmt =                                                         
  | If of expr * stmt * stmt         (* Conditional                 *)
  | While of expr * stmt             (* While loop                  *)
  | For of stmtordec * expr * expr * stmt                          
  | Switch of expr * stmt list
  | Case of expr * stmt
  | Expr of expr                     (* Expression statement   e;   *)
  | Return of expr option            (* Return from method          *)
  | Block of stmtordec list          (* Block: grouping and scope   *)
  | Try  of stmt * stmt list
  | Catch of myexception * stmt
  | Throw of myexception
  | Break
  | Continue

and  myexception= 
  | Exception of string  

and stmtordec =                                                    
  | Dec of typ * string              
  | DeclareAndAssign of typ * string * expr
  | Stmt of stmt                  
     

and topdec = 
  | Fundec of typ option * string * (typ * string) list * stmt
  | Vardec of typ * string
  | VardecAndAssign of typ * string * expr

and program = 
  | Prog of topdec list
